package com.slipper.ai.model.embedding;

import com.slipper.ai.model.embedding.support.*;
import com.slipper.exception.CommonException;
import com.slipper.system.ai.bo.AiModelBO;
import org.springframework.ai.embedding.EmbeddingModel;

import java.util.HashMap;
import java.util.Map;

public class EmbeddingModelFactory {
    private static final Map<String, EmbeddingModelBuilder> builderMap = new HashMap<>() {{
        put("ollama", new OllamaEmbeddingModelBuilder());
        put("zhipuai", new ZhipuaiEmbeddingModelBuilder());
        put("openai", new OpenAiEmbeddingModelBuilder());
        put("qianfan", new QianFanEmbeddingModelBuilder());
        put("dashscope", new DashScopeEmbeddingModelBuilder());
    }};

    public static EmbeddingModel create(AiModelBO model) {
        EmbeddingModelBuilder builder = builderMap.get(model.getSupplierCode());
        if (builder == null) {
            throw new CommonException("不支持此供应商标识[" + model.getSupplierCode() + "]不存在！");
        }
        return builder.build(model);
    }
}
